local ads__guishou = fk.CreateSkill{
  name = "ads__guishou",
  tags = { Skill.Limited },
}

Fk:loadTranslationTable {
  ["ads__guishou"] = "规守",
  [":ads__guishou"] = "限定技，出牌阶段，你可以回复任意点体力，直到下回合开始，你计算与其他角色的距离-X，且你可以摸X张非【杀】牌"..
  "（X为你以此法回复的体力）。",

  ["@ads__guishou-turn"] = "规守",
  ["#ads__guishou"] = "规守：回复任意点体力，直到下回合开始与其他角色减等量距离，可摸等量张非杀牌",

  ["$ads__guishou1"] = "轻兵出子午，直取魏王都。",
  ["$ads__guishou2"] = "哼，丞相奇谋为短，吾以涉险为长！",
}

ads__guishou:addEffect("active", {
  anim_type = "offensive",
  prompt = "#ads__guishou",
  card_num = 0,
  target_num = 0,
  interaction = function(self, player)
    return UI.Spin {
      from = 1,
      to = player.maxHp - player.hp,
    }
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(ads__guishou.name, Player.HistoryGame) == 0 and player.hp < player.maxHp
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    local toRecover = self.interaction.data
    room:recover({
      who = player,
      num = toRecover,
      recoverBy = player,
      skillName = ads__guishou.name
    })
    room:addPlayerMark(player, "@ads__guishou-turn", toRecover)
    
    local drawnCards = player.room:drawCards(player, toRecover, ads__guishou.name)
    local nonSlashCards = {}
    
    for _, cardId in ipairs(drawnCards) do
      local card = Fk:getCardById(cardId)
      if card.trueName ~= "slash" then
        table.insert(nonSlashCards, cardId)
      end
    end
    
    if #nonSlashCards > 0 then
      room:moveCards({
        ids = nonSlashCards,
        to = player,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonDraw,
        skillName = ads__guishou.name,
        proposer = player,
      })
    end
    
    local slashCards = {}
    for _, cardId in ipairs(drawnCards) do
      local card = Fk:getCardById(cardId)
      if card.trueName == "slash" then
        table.insert(slashCards, cardId)
      end
    end
    
    if #slashCards > 0 then
      room:moveCards({
        ids = slashCards,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        skillName = ads__guishou.name,
        proposer = player,
      })
    end
  end,
})



ads__guishou:addEffect("distance", {
  correct_func = function(self, from, to)
    return -from:getMark("@ads__guishou-turn")
  end,
})

ads__guishou:addEffect(fk.EventPhaseStart, {
  can_trigger = function(self, event, target, player, data)
    return target:getMark("@ads__guishou-turn") > 0 and target.phase == Player.Start
  end,
  on_trigger = function(self, event, target, player, data)
    local room = target.room
    room:setPlayerMark(target, "@ads__guishou-turn", 0)
  end,
})

return ads__guishou